<?php
namespace ManiaLivePlugins\MLEPP\ServerInfo\Gui\Controls;

use ManiaLib\Gui\Elements\Button;
use ManiaLive\Gui\Windowing\Controls\Pager;
use ManiaLivePlugins\MLEPP\ServerInfo\ServerInfo;
use ManiaLive\Gui\Handler\GuiHandler;
use ManiaLib\Gui\Elements\Label;
use ManiaLive\Features\ChatCommand\Interpreter; // this one holds the chatcommands

class CommandsTab extends \ManiaLive\Gui\Windowing\Controls\Tab
{
    private $pgServerCommands;    
    protected $registeredCommands = array();
    
    function initializeComponents()
    {
        $this->pgServerCommands = new Pager();
        $this->pgServerCommands->setPosition(0,5);
        $this->pgServerCommands->setStretchContentX(true);
        $this->addComponent($this->pgServerCommands);
    }
    
    
    function commandList($login)
    {    
        $interpreter = Interpreter::getInstance();
        $lastName = "";
        $this->pgServerCommands->clearItems();
        foreach ($interpreter ->getRegisteredCommands() as $commands)
        {
            foreach($commands as $argumentCount => $command)
            {
                if($command->isPublic && (!count($command->authorizedLogin) || in_array($login, $command->authorizedLogin)))
                {
                 if ($command->name != $lastName) { 
                      $item = new ListItem();
                        $item->label->setText(' /'.$command->name);
                        $this->pgServerCommands->addItem($item);
                        $lastName = $command->name;
                        }
                }
            }
        }
         
    }    

    
    function onResize()
    {
        $this->pgServerCommands->setSize($this->sizeX, $this->sizeY-5);
    }
    
}

?>